import codecs
import numpy as np
import turtle


def my_random():
    g = np.random.default_rng(seed=42)
    print(g.integers(1, 9, 3))
    print(g.integers(1, 9, 3))
    print(g.integers(1, 9, 3))
    print(np.random.randint(1, 9))
my_random()


def my_draw():
    # 创建一个Turtle对象
    t = turtle.Turtle()

    # 绘制正方形
    for _ in range(4):
        t.forward(100)  # 向前移动100单位
        t.right(90)    # 向右转90度

    # 结束绘图
    turtle.done()
my_draw()

def my_file_write():
    # 文件写入
    with codecs.open("sample2.txt", "a+", encoding="utf-8") as fi:
        fi.write("中文写入")
my_file_write()

def my_other():
    # 条件分支
    my_str = "你好，世界！"
    x = 6
    if x % 2 == 0:
        print(my_str)

    # 命令行获取
    aa = input("请输入：")
    print(aa)
    # 内置文件处理
    f = open("sample.txt", "a+")
    print(f.name)
    print(f.closed)
    print(f.mode)
    f.write("程序写入新文字：" + aa + "。")
    print("当前的文件位置：", f.tell())
    f.seek(0, 0)
    r = f.read()
    print("文件内容\n")
    print(r)
    f.close()

    # numpy 数组
    a = np.array([[2, 3, 4], [3, 3, 3], [4, 4, 4], [5, 6, 7]])
    b = a.min(1)
    print(b)
    c = a.shape[0]
    print(c)
